package com.huan.dml;

import com.huan.Call;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

public class DeleteDataAPI {


    //删除数据
    public static void deleteData(String tableName,String rowKey,String cf,String cn) throws IOException {

        //1.读取表对象
        Connection conn = Call.conn;
        Table table =  conn.getTable( TableName.valueOf( tableName ) );

        //2.构建删除对象
        Delete delete = new Delete( Bytes.toBytes( rowKey ) );

//        //2.1指定列族
//        delete.addFamily( Bytes.toBytes( cf ));
//
//        //2.2指定列
//        delete.addColumn( Bytes.toBytes( cf ),Bytes.toBytes( cn ) );

        //3.执行删除操作
        table.delete( delete);

        //4.关闭连接
        table.close();
    }

    public static void main(String[] args) throws IOException {

        deleteData( "stu1","1001","info1" , "age");

        Call.close();
    }

}
